| Soares Chen | 5dbbd5f | 2017-07-10 09:56:09 | [diff] [blame] | 1 | <!doctype html> |
| 2 | <meta charset=utf-8> |
| 3 | <title>RTCPeerConnection.prototype.setLocalDescription pranswer</title> |
| 4 | <script src="/resources/testharness.js"></script> |
| 5 | <script src="/resources/testharnessreport.js"></script> |
| 6 | <script src="RTCPeerConnection-helper.js"></script> |
| 7 | <script> |
| 8 | 'use strict'; |
| 9 | |
| 10 | // Test is based on the following editor draft: |
| 11 | // https://w3c.github.io/webrtc-pc/archives/20170605/webrtc.html |
| 12 | |
| 13 | // The following helper functions are called from RTCPeerConnection-helper.js: |
| 14 | // generateOffer |
| 15 | // generateAnswer |
| 16 | // assert_session_desc_equals |
| 17 | // test_state_change_event |
| 18 | |
| 19 | /* |
| 20 | 4.3.2. Interface Definition |
| 21 | [Constructor(optional RTCConfiguration configuration)] |
| 22 | interface RTCPeerConnection : EventTarget { |
| 23 | Promise<void> setLocalDescription( |
| 24 | RTCSessionDescriptionInit description); |
| 25 | |
| 26 | readonly attribute RTCSessionDescription? localDescription; |
| 27 | readonly attribute RTCSessionDescription? currentLocalDescription; |
| 28 | readonly attribute RTCSessionDescription? pendingLocalDescription; |
| 29 | |
| 30 | Promise<void> setRemoteDescription( |
| 31 | RTCSessionDescriptionInit description); |
| 32 | |
| 33 | readonly attribute RTCSessionDescription? remoteDescription; |
| 34 | readonly attribute RTCSessionDescription? currentRemoteDescription; |
| 35 | readonly attribute RTCSessionDescription? pendingRemoteDescription; |
| 36 | ... |
| 37 | }; |
| 38 | |
| 39 | 4.6.2. RTCSessionDescription Class |
| 40 | dictionary RTCSessionDescriptionInit { |
| 41 | required RTCSdpType type; |
| 42 | DOMString sdp = ""; |
| 43 | }; |
| 44 | |
| 45 | 4.6.1. RTCSdpType |
| 46 | enum RTCSdpType { |
| 47 | "offer", |
| 48 | "pranswer", |
| 49 | "answer", |
| 50 | "rollback" |
| 51 | }; |
| 52 | */ |
| 53 | |
| 54 | /* |
| 55 | 4.3.1.6. Set the RTCSessionSessionDescription |
| 56 | 2.3. If the description's type is invalid for the current signaling state of |
| 57 | connection, then reject p with a newly created InvalidStateError and abort |
| 58 | these steps. |
| 59 | |
| 60 | [jsep] |
| 61 | 5.5. If the type is "pranswer" or "answer", the PeerConnection |
| 62 | state MUST be either "have-remote-offer" or "have-local-pranswer". |
| 63 | */ |
| 64 | promise_test(t => { |
| 65 | const pc = new RTCPeerConnection(); |
| 66 | |
| Rick Waldron | 5445fa3 | 2017-08-30 21:53:59 | [diff] [blame] | 67 | return pc.createOffer() |
| Soares Chen | 5dbbd5f | 2017-07-10 09:56:09 | [diff] [blame] | 68 | .then(offer => |
| 69 | promise_rejects(t, 'InvalidStateError', |
| 70 | pc.setLocalDescription({ type: 'pranswer', sdp: offer.sdp }))); |
| 71 | |
| 72 | }, 'setLocalDescription(pranswer) from stable state should reject with InvalidStateError'); |
| 73 | |
| 74 | /* |
| 75 | 4.3.1.6 Set the RTCSessionSessionDescription |
| 76 | 2.2.2. If description is set as a local description, then run one of the |
| 77 | following steps: |
| 78 | - If description is of type "pranswer", then set |
| 79 | connection.pendingLocalDescription to description and signaling state to |
| 80 | have-local-pranswer. |
| 81 | */ |
| 82 | promise_test(t => { |
| 83 | const pc = new RTCPeerConnection(); |
| 84 | test_state_change_event(t, pc, ['have-remote-offer', 'have-local-pranswer']); |
| 85 | |
| Rick Waldron | 5445fa3 | 2017-08-30 21:53:59 | [diff] [blame] | 86 | return pc.createOffer({ offerToReceiveVideo: true }) |
| Soares Chen | 5dbbd5f | 2017-07-10 09:56:09 | [diff] [blame] | 87 | .then(offer => |
| 88 | pc.setRemoteDescription(offer) |
| 89 | .then(() => pc.createAnswer()) |
| 90 | .then(answer => { |
| 91 | const pranswer = { type: 'pranswer', sdp: answer.sdp }; |
| 92 | |
| 93 | return pc.setLocalDescription(pranswer) |
| 94 | .then(() => { |
| 95 | assert_equals(pc.signalingState, 'have-local-pranswer'); |
| 96 | |
| 97 | assert_session_desc_equals(pc.remoteDescription, offer); |
| 98 | assert_session_desc_equals(pc.pendingRemoteDescription, offer); |
| 99 | assert_equals(pc.currentRemoteDescription, null); |
| 100 | |
| 101 | assert_session_desc_equals(pc.localDescription, pranswer); |
| 102 | assert_session_desc_equals(pc.pendingLocalDescription, pranswer); |
| 103 | assert_equals(pc.currentLocalDescription, null); |
| 104 | |
| 105 | assert_equals(pc.pendingRemoteDescription, null); |
| 106 | }); |
| 107 | })); |
| 108 | }, 'setLocalDescription(pranswer) should succeed'); |
| 109 | |
| 110 | promise_test(t => { |
| 111 | const pc = new RTCPeerConnection(); |
| 112 | test_state_change_event(t, pc, ['have-remote-offer', 'have-local-pranswer']); |
| 113 | |
| Rick Waldron | 5445fa3 | 2017-08-30 21:53:59 | [diff] [blame] | 114 | return pc.createOffer({ offerToReceiveVideo: true }) |
| Soares Chen | 5dbbd5f | 2017-07-10 09:56:09 | [diff] [blame] | 115 | .then(offer => |
| 116 | pc.setRemoteDescription(offer) |
| 117 | .then(() => pc.createAnswer()) |
| 118 | .then(answer => { |
| 119 | const pranswer = { type: 'pranswer', sdp: answer.sdp }; |
| 120 | |
| 121 | return pc.setLocalDescription(pranswer) |
| 122 | .then(() => pc.setLocalDescription(pranswer)); |
| 123 | })); |
| 124 | }, 'setLocalDescription(pranswer) can be applied multiple times while still in have-local-pranswer'); |
| 125 | |
| 126 | promise_test(t => { |
| 127 | const pc = new RTCPeerConnection(); |
| 128 | test_state_change_event(t, pc, ['have-remote-offer', 'have-local-pranswer', 'stable']); |
| 129 | |
| Rick Waldron | 5445fa3 | 2017-08-30 21:53:59 | [diff] [blame] | 130 | return pc.createOffer({ offerToReceiveVideo: true }) |
| Soares Chen | 5dbbd5f | 2017-07-10 09:56:09 | [diff] [blame] | 131 | .then(offer => |
| 132 | pc.setRemoteDescription(offer) |
| 133 | .then(() => pc.createAnswer()) |
| 134 | .then(answer => { |
| 135 | const pranswer = { type: 'pranswer', sdp: answer.sdp }; |
| 136 | |
| 137 | return pc.setLocalDescription(pranswer) |
| 138 | .then(() => pc.setLocalDescription(answer)) |
| 139 | .then(() => { |
| 140 | assert_equals(pc.signalingState, 'stable'); |
| 141 | assert_session_desc_equals(pc.localDescription, answer); |
| 142 | assert_session_desc_equals(pc.remoteDescription, offer); |
| 143 | |
| 144 | assert_session_desc_equals(pc.currentLocalDescription, answer); |
| 145 | assert_session_desc_equals(pc.currentRemoteDescription, offer); |
| 146 | |
| 147 | assert_equals(pc.pendingLocalDescription, null); |
| 148 | assert_equals(pc.pendingRemoteDescription, null); |
| 149 | }); |
| 150 | })); |
| 151 | }, 'setLocalDescription(answer) from have-local-pranswer state should succeed'); |
| 152 | |
| 153 | </script> |